package chapter04

import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.SparkSession

object Test07_movie {
  def main(args: Array[String]): Unit = {
    Logger.getLogger("org.apache.spark").setLevel(Level.WARN)
    val spark = SparkSession.builder()
      .master("local[*]")
      .appName("movie")
      .getOrCreate()
    import spark.implicits._
    val sc = spark.sparkContext
    val df = sc.textFile("input/ratings.dat")
      .map(e => e.split("::"))
      .map(e => (e(0).toInt, e(1).toInt, e(2).toInt, e(3).toLong))
      .toDF("userId", "movieId", "rating", "timestamp")
    df.groupBy("movieId")
      .sum("rating")
      .orderBy($"sum(rating)".desc)
      .show(5)
  }
}
